package com.litchishell.feartures.main;

import com.litchishell.feartures.enums.Color;
import com.litchishell.feartures.pojo.Apple;
import com.litchishell.feartures.predicate.ApplePredicate;
import com.litchishell.feartures.predicate.impl.AppleFancyPredicate;
import com.litchishell.feartures.predicate.impl.AppleSimplePredicate;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LitchiShell
 * @description: 行为参数化传递代码
 * @create 2021-11-14
 */
public class Test1 {
    public static void main(String[] args) {
        ArrayList<Apple> apples = new ArrayList<Apple>();
        Apple apple1 = new Apple(12, Color.RED);
        Apple apple2 = new Apple(14, Color.GREEN);
        Apple apple3 = new Apple(42, Color.RED);
        Apple apple4 = new Apple(52, Color.GREEN);
        Apple apple5 = new Apple(6, Color.RED);
        Apple apple6 = new Apple(17, Color.GREEN);
        apples.add(apple1);
        apples.add(apple2);
        apples.add(apple3);
        apples.add(apple4);
        apples.add(apple5);
        apples.add(apple6);
        prettyPrintApple(apples,new AppleFancyPredicate());
        prettyPrintApple(apples, new AppleSimplePredicate());
        // lambda 方式：prettyPrintApple(apples,(Apple apple) -> Color.RED.equals(apple.getColor()));
    }

    public static void prettyPrintApple(List<Apple> apples, ApplePredicate predicate) {
        for (Apple apple : apples) {
            String output = predicate.accept(apple);
            System.out.println(output);
        }
    }
}
